/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-03-14
 * Time: 19:26
 */
class Student{
    public String name;
    public int age;
    public String stuNum;
    private static String classNum = "11";

    public Student(String name, int age, String stuNum) {
        this.name = name;
        this.age = age;
        this.stuNum = stuNum;
        Student.classNum = "14";
        System.out.println("调用了构造方法");
    }
    //当类加载的时候，就会被触发，类只加载一次
    static {
        classNum = "12";
//        name = "二蛋";静态的代码块中无法访问非静态的成员变量
        System.out.println("调用了静态代码块");
    }
    {
        classNum = "15";
        System.out.println("调用了实例代码块");
    }

    //非静态的不能放到静态的方法中
    public static String getClassNum(){
        return classNum;
    }

    @Override
    public String toString() {
        getClassNum();//非静态方法可以调用静态方法
        /*return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", stuNum='" + stuNum + '\'' +
                '}';*/
        return "666";
    }
}
public class Test {
    public static void main(String[] args) {
        Student student = new Student("张三", 17, "2024304");
        //System.out.println(student.getClassNum());
        System.out.println(student.toString());
        System.out.println("==========================");
        //静态的只会执行一次，也就是类只会加载一次
        Student student1 = new Student("李四", 18 , "2024305");

    }
}
